<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #ad{
      width: 200px;
      height: 200px;
      background-color: coral;
    }
  </style>
</head>
<body>
  <div id="ad"></div>
  <script>
    //1 点击2秒后变颜色
    let ad = document.getElementById('ad')
    ad.addEventListener('click',function(){//可以添加多个事件 不会覆盖
      //保存this
      // let _this = this
      setTimeout(function(){
        // _this.style.background = 'pink'
      }, 2000)

      setTimeout(() => {
        this.style.background = 'pink'
      },2000)
    })

    //2 从数组中返回偶数的元素
    const arr = [1,23,6,98,100]
    // const result = arr.filter(function(item){
    //   if(item%2 === 0){
    //     return true
    //   }else{
    //     return false
    //   }
    // })

    const result = arr.filter(item => item%2 ===0)
    console.log(result)

    //箭头函数适合与this无关的回调，定时器，数组的方法回调
    //不适合与this有关的回调，事件回调、对象的方法

  </script>
</body>
</html>